#!/bin/bash

# Asurada SSO Docker 构建脚本

echo "🚀 开始构建 Asurada SSO Docker 镜像..."

# 检查Docker是否安装
if ! command -v docker &> /dev/null; then
    echo "❌ Docker 未安装，请先安装 Docker"
    echo "📖 参考 DOCKER_SETUP.md 文件进行安装"
    exit 1
fi

# 检查jar文件是否存在
if [ ! -f "target/asurada-sso-0.0.1-SNAPSHOT.jar" ]; then
    echo "📦 jar文件不存在，开始构建..."
    mvn clean package -DskipTests
    if [ $? -ne 0 ]; then
        echo "❌ Maven 构建失败"
        exit 1
    fi
fi

# 构建Docker镜像
echo "🐳 构建 Docker 镜像..."
docker build -t asurada-sso:latest .

if [ $? -eq 0 ]; then
    echo "✅ Docker 镜像构建成功！"
    echo "📋 镜像信息："
    docker images | grep asurada-sso
    echo ""
    echo "🚀 运行命令："
    echo "docker run -d --name asurada-sso -p 8080:8080 asurada-sso:latest"
else
    echo "❌ Docker 镜像构建失败"
    exit 1
fi